#!/usr/bin/env node

const fs = require('fs'),
      log = console.log;

switch(process.argv.length){
  case 4:{  //hard link    node 13-ln.js src link
    let src = process.argv[2],
        lnk = process.argv[3];
    try{
      fs.linkSync(src,lnk);
    }catch(e){
      log(e.message);
      process.exit(1);
    }
    break;
  }

  case 5:{  //soft link   node 13-ln.js -s src lnk
    let opt = process.argv[2],
        src = process.argv[3],
        lnk = process.argv[4];
    if(opt === '-s'){
      try{
        fs.symlinkSync(src,lnk);
      }catch(e){
        log(e.message);
        process.exit(2);
      }
    }else{
      log('命令行参数不正确！');
    }
     break;
  }

  default:
    console.error('命令行参数不正确！');
    process.exit(3);
}
